package config

import (
	"os"
	"strings"
)

func parseCmdArgs() ParsedData {
	m := ParsedData{}
	for _, arg := range os.Args[1:] {
		if arg == "" {
			continue
		}
		if arg[0] != '-' {
			continue
		}
		if arg == "--help" {
			fShowUsage = true
		}
		ss := strings.SplitN(arg, "=", 2)
		if len(ss) != 2 {
			ss = append(ss, "")
		}
		k := strings.Replace(strings.Trim(ss[0], "-"), "-", ".", -1)
		checkFields(k)
		m.Add(k, parseString(ss[1]))
	}
	return m
}

//

func getConfPath() string {
	for _, arg := range os.Args[1:] {
		if arg == "" {
			continue
		}
		if arg[0] == '-' {
			continue
		}
		if arg[0] == '/' || arg[0] == '.' {
			return arg
		}
		return File(arg)
	}
	return ""
}
